class WFPlayer extends xPlayer;

//for testing purposes
var vector vMinionSpawnLoc;
var WFPlayer OldPlayer;

defaultproperties
{
     PawnClass=class'bblock.WFPawn'
     bCollideWorld = true;
}


function SetPawnClass(string inClass, string inCharacter)
{
    super.SetPawnClass("bblock.WFPawn", inCharacter);
}


exec function printinfo(){
     ClientMessage("self.name:"$self.name);
     ClientMessage("self.tag:"$self.PawnClass);
}

exec function loc(){
     ClientMessage(pawn.Location);
}

exec function locationmarker(){
    local WFLocationMarker k;

    foreach AllActors (class'WFLocationMarker', k) {
        if (string(k.Name) == "WFLocationMarker0"){
            ClientMessage("WFLocationMaker0 found at: "@k.Location);
        }
    }
}

exec function listall(){
    local Actor A;
	local int i;
    // Go through all actors in the level.
    ClientMessage("getting data on all WFPlayers");
    i=1;
    foreach AllActors (class'Actor', A) {
      if (A == class'WFPlayer' || A == class'KObject'){
      ClientMessage("player "@i@" loc:"@A.Location);
      i++;
      }
	}
}

function NotifyTakeHit ( pawn InstigatedBy, vector HitLocation, int Damage, class<DamageType> damageType, vector Momentum ){
    Log("Hit by " @ damageType);
}

simulated function Touch(Actor Other) {
    ClientMessage("Touched by " @ Other.name);
}
/*
simulated event TriggerEvent(name eventName, Actor aSentEvent, Pawn pCausedEvent){
    ClientMessage("TriggerEvent RECIEVED!!!");
    ClientMessage("event name: "@eventName@", sentevent: "@aSentEvent.name@", caused event: "@pCausedEvent.name);
    return;
}
*/

event Trigger(Actor aBroadcaster, Pawn pTriggerer){
    local vector vLoc;
    local Actor wfNewBody;
    local PlayerController Possessor;

    //ClientMessage("Just Basic Trigger RECIEVED!!!");
   // ClientMessage("self.name: "@self.name@", pTriggerer.name: "@pTriggerer.name);
    //ClientMessage("pawn.name: "@pawn.name);

    local Actor spawnpoint;

    spawnpoint = GetActorByName("PlayerStart1");
    ClientMessage("spawnobject name check: " @ spawnpoint.name);
    ClientMessage("spawnobject loc check: " @ spawnpoint.Location);

    //erm...i dont think this is a very good check...but i'm using it for the time being
    if (pawn.name == pTriggerer.name){
        vLoc = getPlayerLoc();

        if(pTriggerer != none && pTriggerer.Controller != none
            && PlayerController(pTriggerer.Controller) != None)
        {
           ClientMessage("MADE IT!!!!!!!!!");

           wfNewBody=Spawn(class'WFPlayer',pTriggerer,,spawnpoint.Location+Vect(0,0,10),);
           Possessor=PlayerController(pTriggerer.Controller);

           if (Possessor == none){
              ClientMessage("Error: Possessor == none!");
           }
           else{
                ClientMessage("unpossessing...");
                Possessor.Unpossess();

                ClientMessage("possessing new body...");
                Instigator.SetOwner(Possessor);
                Possessor.Possess(Pawn(wfNewBody));
           }
        }
    }
}


/*************************************************
     FUNCTIONS THAT WILL PROBABLY BE REMOVED
**************************************************/

private function vector getPlayerLoc(){
    ClientMessage("WFPlayer loc: "@Pawn.Location);
    return Pawn.Location;
}

private function vector wfLocMark(){
    local WFLocationMarker k;

    foreach AllActors (class'WFLocationMarker', k) {
        if (string(k.Name) == "WFLocationMarker0"){
            return k.Location;
        }
    }
}

function actor GetActorByName(string s){
    local Actor A;
	// Go through all actors in the level.
	log( "looking for actors1:" );

    foreach AllActors (class'Actor', A) {
      if (s ~= string(A.name))
		{
		    ClientMessage("Final Target Found: " @ A);
		    log("final Target Found: " @ A);
			return A;
		}
	}
	return none;
}



